package com.ftg.learn.bus.role.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ftg.learn.bus.role.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 添加
     * @param role
     * @return
     */
    @Insert("insert into role values (#{role_id},#{role_name},#{rolestate},#{note})")
    int insert(Role role);

    /**
     * 修改
     * @param role
     * @return
     */
    @Update("update role set role_name=#{role_name},rolestate=#{rolestate},note=#{note} where role_id=#{role_id}")
    int update(Role role);

    /**
     * 删除
     * @param id
     * @return
     */
    @Delete("delete from role where role_id = #{role_id}")
    int delete(String id);

    /**
     * 多删
     * @param role_ids
     * @return
     */
    @Delete("<script>delete from userole_control where role_id in" +
                "<foreach collection='role_ids'  item='item' open='(' separator=',' close=')'  >" +
                    "#{item}" +
                "</foreach>" +
            "</script>")
    int deleteForUserole_controlByrole_ids(List<String> role_ids);

    @Delete("<script>delete from userole_control where user_id in" +
                "<foreach collection='user_ids'  item='item' open='(' separator=',' close=')'  >" +
                    "#{item}" +
                "</foreach>" +
            "</script>")
    int deleteForUserole_controlByuser_ids(List<String> user_ids);

    @Select("<script>select user_id from userole_control where role_id in"+
                "<foreach collection='role_ids'  item='item' open='(' separator=',' close=')'  >" +
                    "#{item}" +
                "</foreach>" +
            "</script>")
    List<String> selectUser_id(List<String> role_ids);


}
